
package com.dps.omc.action;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dps.omc.model.User;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dps.common.domain.view.BizData4Page;
import com.dps.omc.model.JobBizType;
import com.dps.omc.service.IJobBizTypeService;
import com.dps.common.utils.IdGenerator;
import com.dps.common.utils.JsonResult;
import com.dps.common.utils.PageParam;
import com.dps.common.utils.Constants;

@Controller
public class JobBizTypeAction extends AbstractAdminController<IJobBizTypeService>{

    @Autowired
    private IJobBizTypeService jobBizTypeService;
    
    @RequestMapping(value="/jobbiztype/list")
    public String list(JobBizType jobBizType,ModelMap model,PageParam pageParam,HttpServletRequest request,HttpServletResponse response){

        //获取参数
    	Map<String, Object> conditions = getQueryMap(jobBizType); 	
    	BizData4Page<JobBizType> pageCtx = doPage(model, conditions, pageParam);
    	model.addAttribute("jobBizType", jobBizType);
    	return "/module/jobbiztype/list";
    }    
    
    @RequestMapping(value="/jobbiztype/add")
    public String add(ModelMap model,HttpServletRequest request,HttpServletResponse response){

    	model.addAttribute("jobBizType", new JobBizType());
        return "module/jobbiztype/edit";
    }    
    
    @RequestMapping(value="/jobbiztype/edit")
    public String edit(String id,ModelMap model,HttpServletRequest request,HttpServletResponse response){
    	
    	JobBizType jobBizType = jobBizTypeService.fetch(id);
    	model.addAttribute("jobBizType", jobBizType);
        return "module/jobbiztype/edit";
    }    
    
    @RequestMapping(value="/jobbiztype/save")
    @ResponseBody
    public String save(HttpServletRequest request,JobBizType jobBizType){
		boolean isAddNew = StringUtils.isBlank(jobBizType.getId())?true:false;
        User user=getCurrentUser();
		if(isAddNew)
		{
			jobBizType.setId(IdGenerator.createNewId());
            jobBizType.setCreaterId(user.getId());
            jobBizType.setCreaterName(user.getRealName());
			jobBizTypeService.add(jobBizType);
		}
		else
		{
			jobBizTypeService.update(jobBizType);
		}
        return JsonResult.saveSuccessClose(Constants.MAIN_TAB).toString();
    }    
    
    @RequestMapping(value="/jobbiztype/delete")
    @ResponseBody
    public String delete(String ids,HttpServletRequest request){
    	
    	jobBizTypeService.deleteByIds(ids);
    	return JsonResult.DELETE_SUCCESS.toString();
    }       
	
    protected Map getQueryMap(JobBizType jobBizType)
    {
    	Map<String, Object> conditions = new HashMap();
    	
		conditions.put("jobId", jobBizType.getJobId());		
		conditions.put("bizType", jobBizType.getBizType());		
		conditions.put("createrId", jobBizType.getCreaterId());		
		conditions.put("createrName", jobBizType.getCreaterName());		
		conditions.put("createDate", jobBizType.getCreateDate());		
    	return conditions;
    }

    @Override
    protected IJobBizTypeService getMainService() {
        return jobBizTypeService;
    }

    @Override
    protected String getMainObjName() {
        return "jobbiztype";
    }

    @Override
    protected String getViewTitle() {
        return "jobbiztype";
    }
}
